﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Way.Lib;

namespace CheckIn.ToolsHost.Infrastructures
{
    public class NumberResultService
    {
        Dictionary<int, string[]> _dict = new Dictionary<int, string[]>();
        public NumberResultService()
        {
            var items = File.ReadAllText(@"NumberResult.json", Encoding.UTF8).Split('\n').Select(m=>m.Trim()).Where(m=>m.Length > 0)
                .Select(m=>m.Split(','));
            foreach( var item in items )
            {
                if (item.Length != 3)
                    throw new Exception("数据错误：" + item.ToJsonString());
                _dict[Convert.ToInt32(item[0])] = new string[] { item[1], item[2] };
            }
        }

        public string[] GetResult(int number)
        {
            if(_dict.TryGetValue(number,out string[] ret))
            {
                return ret;
            }
            return null;
        }
    }
}
